package com.nd.android.u.ui.business4starapp;

import java.io.File;

import com.nd.android.u.business.com.AbstractUploadDownload;
import com.nd.android.u.business.com.ProgressDownloadManager;
import com.nd.android.u.controller.innerInterface.IShareFileDataSupplier;
import com.nd.android.u.ui.business4starapp.FileCom;

/**
 * 文件下载
 * 
 * <br>
 * Created 2014-9-1 下午2:09:09
 * 
 * @version
 * @author youy
 * 
 * @see
 */
public class ShareFileDownload_File extends AbstractUploadDownload {

    @Override
    public void doRequest(IShareFileDataSupplier operation, int type) {
        this.type = type;
        this.operation = operation;
        ProgressDownloadManager manager = new ProgressDownloadManager();
        manager.setOnDownloadListener(donwloadListener);
        /**
         * 此URL是旧的url，新的只需要得到fkey再组成url进行下载
         */
        String url = operation.getResource(type);
        if (url != null && url.indexOf("k=") > -1) {
            url = url.substring(url.indexOf("k=") + 2);
        }
        url = FileCom.FILE_DOWN_URL + url;
        File file = operation.getFile();
        if (file == null) {
            operation.onFail("null file", 0, type);
            return;
        }
        manager.startDownload(url, file);
    }
    
    @Override
    public String getShareFileUrl(String fKey, String fileOwner, int messageType) {
    	return FileCom.FILE_DOWN_URL+fKey;
    }
}
